<template>
  <div class="zoom-control">
    <button 
      class="zoom-btn zoom-in" 
      @click="handleZoomIn"
      :disabled="!isMapReady"
      title="放大"
    >
      <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
        <path d="M8 3V13M3 8H13" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
      </svg>
    </button>
    <button 
      class="zoom-btn zoom-out" 
      @click="handleZoomOut"
      :disabled="!isMapReady"
      title="缩小"
    >
      <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
        <path d="M3 8H13" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
      </svg>
    </button>
    <div class="zoom-level" v-if="showZoomLevel">
      {{ currentZoom }}
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, computed } from 'vue'

interface Props {
  // 是否显示缩放级别
  showZoomLevel?: boolean
  // 地图是否准备就绪
  isMapReady?: boolean
  // 当前缩放级别
  currentZoom?: number
}

const props = withDefaults(defineProps<Props>(), {
  showZoomLevel: true,
  isMapReady: false,
  currentZoom: 0
})

interface Emits {
  zoomIn: []
  zoomOut: []
}

const emit = defineEmits<Emits>()

const handleZoomIn = () => {
  if (props.isMapReady) {
    emit('zoomIn')
  }
}

const handleZoomOut = () => {
  if (props.isMapReady) {
    emit('zoomOut')
  }
}
</script>

<style lang="less" scoped>
.zoom-control {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.zoom-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: #333;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  border-radius: 4px;
  
  &:hover:not(:disabled) {
    background: rgba(64, 158, 255, 0.1);
    color: #409eff;
  }
  
  &:active:not(:disabled) {
    background: rgba(64, 158, 255, 0.2);
  }
  
  &:disabled {
    color: #ccc;
    cursor: not-allowed;
  }
  
  &.zoom-in {
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  }
}

.zoom-level {
  padding: 8px 12px;
  text-align: center;
  font-size: 12px;
  color: #666;
  font-weight: 500;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  background: rgba(248, 249, 250, 0.8);
  border-radius: 0 0 6px 6px;
}
</style>